package models

import (
	"time"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Username    string        `json:"username"`
	Password    string        `json:"-"`
	Email       string        `json:"email"`
	Nickname    string        `json:"nickname"`
	Avatar      string        `json:"avatar"`
	IsOnline    bool          `json:"is_online"`
	VipInfo     VipInfo       `json:"vip_info" gorm:"embedded;embeddedPrefix:vip_"`
	LoginRecord []LoginRecord `json:"-"`
}

// 会员信息
type VipInfo struct {
	Level      int        `json:"level"`
	ExpireTime *time.Time `json:"expire_time" gorm:"default:null"`
}

// 登录记录
type LoginRecord struct {
	gorm.Model
	UserID    uint      `json:"user_id" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	LoginTime time.Time `json:"login_time"`
	Ip        string    `json:"ip"`
	Address   string    `json:"address"`
}
